// ----------------------------------------------------------------------------
// byte_reader.h
// ----------------------------------------------------------------------------
/*
 Description:
 バイト列を読み込むクラス.
 */
#pragma once
#include <stddef.h>
#include <fw/base/core/noncopyable.h>
#include <fw/base/core/stdinteger.h>

namespace fw
{
	class ByteReader : private NonCopyable
	{
	private:
		const char*		m_data;
		size_t			m_size;
		size_t			m_offset;
		
	public:
		ByteReader();
		ByteReader(const char* data, size_t size);
		
		void		SetBuffer(const char* data, size_t size);
		const char*	GetBuffer() const;
		
		uint8_t		Read8 ();
		uint16_t	Read16();
		uint32_t	Read32();
		uint64_t	Read64();
		
		size_t		GetRemain() const;
		
		void		Seek(size_t pos=0);
		size_t		Tell() const;
		
		template<typename T> T* ReadNew()
		{
			return T::ReadNew(*this);
		}
		
		template<typename T> T  Read()
		{
			return T::Read(*this);
		}
		
	}; // class ByteReader
	
} // namespace fw
